home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 676-700 / 681 / term / source.lha / termTransfer.c < prev    next >
C/C++ Source or Header  |  1992-05-09  |  15KB  |  759 lines

  1. /*
  2. **    $Id: termTransfer.c,v 1.4 92/04/21 16:58:07 olsen Sta Locker: olsen $
  3. **    $Revision: 1.4 $
  4. **    $Date: 92/04/21 16:58:07 $
  5. **
  6. **    File transfer routines
  7. **
  8. **    Copyright © 1990-1992 by Olaf `Olsen' Barthel & MXM
  9. **        All Rights Reserved
  10. */
  11.  
  12. #include "termGlobal.h"
  13.  
  14.     /* The action strings to display. */
  15.  
  16. STATIC UBYTE *SendQuery[3] =
  17. {
  18.     NULL,
  19.     NULL,
  20.     NULL
  21. };
  22.  
  23. STATIC UBYTE *ReceiveQuery[3] =
  24. {
  25.     NULL,
  26.     NULL,
  27.     NULL
  28. };
  29.  
  30.     /* The transfer types to display. */
  31.  
  32. STATIC UBYTE *TransferTypes[3] =
  33. {
  34.     NULL,
  35.     NULL,
  36.     NULL
  37. };
  38.  
  39.     /* SendTextFile(UBYTE *TheFile):
  40.      *
  41.      *    Send a single text file via xpr.
  42.      */
  43.  
  44. VOID
  45. SendTextFile(UBYTE *TheFile)
  46. {
  47.     BYTE OldStatus = Status;
  48.  
  49.     Uploading    = TRUE;
  50.     MultipleFiles    = FALSE;
  51.  
  52.     LocalizeString(SendQuery,MSG_TERMTRANSFER_UPLOAD_FILE_TXT,MSG_TERMTRANSFER_UPLOAD_ASCII_TXT);
  53.     LocalizeString(TransferTypes,MSG_TERMTRANSFER_BINARY_TXT,MSG_TERMTRANSFER_ASCII_TXT);
  54.  
  55.         /* If not initialized, try to set up a new
  56.          * external transfer protocol.
  57.          */
  58.  
  59.     if(!XProtocolBase)
  60.     {
  61.         NewLibrary = FALSE;
  62.  
  63.         xpr_options(0,NULL);
  64.  
  65.         if(NewLibrary)
  66.         {
  67.             if(ProtocolSetup())
  68.             {
  69.                 SaveProtocolOpts();
  70.  
  71.                 strcpy(Config . Protocol,LastXprLibrary);
  72.             }
  73.         }
  74.     }
  75.  
  76.     if(XProtocolBase)
  77.     {
  78.         XprIO -> xpr_filename = TheFile;
  79.  
  80.         if(TransferPanel(SendQuery[TRANSFER_TEXT]))
  81.         {
  82.             BYTE Aborted;
  83.  
  84.             Status = STATUS_UPLOAD;
  85.  
  86.             ClearSerial();
  87.  
  88.             LogAction(LocaleString(MSG_TERMTRANSFER_LOGMSG_INITIATE_UPLOAD_TXT),TransferTypes[TRANSFER_TEXT]);
  89.  
  90.             if(!XProtocolSend(XprIO))
  91.                 Aborted = TRUE;
  92.             else
  93.                 Aborted = FALSE;
  94.  
  95.             if(TransferWindow)
  96.                 WakeUp(TransferWindow,TRUE);
  97.  
  98.             if(Aborted)
  99.                 Say(LocaleString(MSG_GLOBAL_TRANSFER_FAILED_OR_ABORTED_TXT));
  100.             else
  101.                 Say(LocaleString(MSG_GLOBAL_TRANSFER_COMPLETED_TXT));
  102.  
  103.             Status = OldStatus;
  104.  
  105.             DeleteTransferPanel();
  106.  
  107.             if(ReadRequest)
  108.             {
  109.                 ReadRequest -> IOSer . io_Command    = CMD_READ;
  110.                 ReadRequest -> IOSer . io_Data        = ReadBuffer;
  111.                 ReadRequest -> IOSer . io_Length    = 1;
  112.  
  113.                 SetSignal(0,SIG_SERIAL);
  114.  
  115.                 SendIO(ReadRequest);
  116.             }
  117.         }
  118.     }
  119.  
  120.     if(SendAbort && UsesZModem)
  121.         SerWrite(ZModemCancel,20);
  122.  
  123.     SendAbort = FALSE;
  124.  
  125.     Uploading = FALSE;
  126.  
  127.     if(Config . UploadMacro[0])
  128.         SerialCommand(Config . UploadMacro);
  129.  
  130.     DidTransfer = FALSE;
  131. }
  132.  
  133.     /* StartXprReceive():
  134.      *
  135.      *    Receive files via xpr.
  136.      */
  137.  
  138. VOID
  139. StartXprReceive(BYTE Type)
  140. {
  141.     struct FileRequester    *FileRequest;
  142.     UBYTE             DummyBuffer[256];
  143.     BYTE             OldStatus = Status;
  144.  
  145.     LocalizeString(ReceiveQuery,MSG_TERMTRANSFER_DOWNLOAD_FILE_TXT,MSG_TERMTRANSFER_DOWNLOAD_ASCII_TXT);
  146.     LocalizeString(TransferTypes,MSG_TERMTRANSFER_BINARY_TXT,MSG_TERMTRANSFER_ASCII_TXT);
  147.  
  148.         /* Select the download path. */
  149.  
  150.     switch(Type)
  151.     {
  152.         case TRANSFER_BINARY:    DownloadPath = &Config . BinaryDownloadPath[0];
  153.                     break;
  154.  
  155.         case TRANSFER_TEXT:    DownloadPath = &Config . TextDownloadPath[0];
  156.                     break;
  157.  
  158.         case TRANSFER_ASCII:    DownloadPath = &Config . ASCIIDownloadPath[0];
  159.                     break;
  160.     }
  161.  
  162.     BlockWindows();
  163.  
  164.         /* Set up the library if necessary. */
  165.  
  166.     if(!XProtocolBase)
  167.     {
  168.         NewLibrary = FALSE;
  169.  
  170.         xpr_options(0,NULL);
  171.  
  172.         if(NewLibrary)
  173.         {
  174.             if(ProtocolSetup())
  175.             {
  176.                 SaveProtocolOpts();
  177.  
  178.                 strcpy(Config . Protocol,LastXprLibrary);
  179.             }
  180.         }
  181.     }
  182.  
  183.     if(XProtocolBase)
  184.     {
  185.             /* Do we need to ask the user for
  186.              * the destination file name?
  187.              */
  188.  
  189.         if(TransferBits & XPRS_NORECREQ)
  190.         {
  191.                 /* Obviously not, let's open
  192.                  * the transfer info window as
  193.                  * usual and download the file(s).
  194.                  */
  195.  
  196.             if(TransferPanel(ReceiveQuery[Type]))
  197.             {
  198.                 Status = STATUS_DOWNLOAD;
  199.  
  200.                 ClearSerial();
  201.  
  202.                 LogAction(LocaleString(MSG_TERMTRANSFER_LOGMSG_INITIATE_DOWNLOAD_TXT),TransferTypes[Type]);
  203.  
  204.                     /* Receive the data. */
  205.  
  206.                 if(!XProtocolReceive(XprIO))
  207.                     TransferAborted = TRUE;
  208.  
  209.                     /* In case the transfer has been aborted,
  210.                      * flush the input buffer of dirty data.
  211.                      */
  212.  
  213.                 if(TransferAborted)
  214.                     xpr_sflush();
  215.  
  216.                     /* Wake the user up. */
  217.  
  218.                 if(TransferWindow)
  219.                     WakeUp(TransferWindow,TRUE);
  220.  
  221.                 if(TransferAborted)
  222.                 {
  223.                     TransferAborted = FALSE;
  224.  
  225.                     Say(LocaleString(MSG_GLOBAL_TRANSFER_FAILED_OR_ABORTED_TXT));
  226.                 }
  227.                 else
  228.                     Say(LocaleString(MSG_GLOBAL_TRANSFER_COMPLETED_TXT));
  229.  
  230.                 Status = OldStatus;
  231.  
  232.                     /* Queue another read request. */
  233.  
  234.                 if(ReadRequest)
  235.                 {
  236.                     ReadRequest -> IOSer . io_Command    = CMD_READ;
  237.                     ReadRequest -> IOSer . io_Data        = ReadBuffer;
  238.                     ReadRequest -> IOSer . io_Length    = 1;
  239.  
  240.                     SetSignal(0,SIG_SERIAL);
  241.  
  242.                     SendIO(ReadRequest);
  243.                 }
  244.  
  245.                 DeleteTransferPanel();
  246.             }
  247.         }
  248.         else
  249.         {
  250.                 /* Download the file(s). */
  251.  
  252.             if(FileRequest = GetFile(ReceiveQuery[Type],DownloadPath,"",DummyBuffer,NULL,TRUE,FALSE,FALSE,LocaleString(MSG_TERMTRANSFER_RECEIVE_TXT)))
  253.             {
  254.                     /* Save the download path. */
  255.  
  256.                 strcpy(DownloadPath,FileRequest -> rf_Dir);
  257.  
  258.                     /* Install the name of the file to receive. */
  259.  
  260.                 XprIO -> xpr_filename = DummyBuffer;
  261.  
  262.                     /* Open the transfer panel. */
  263.  
  264.                 if(TransferPanel(ReceiveQuery[Type]))
  265.                 {
  266.                     Status = STATUS_DOWNLOAD;
  267.  
  268.                     ClearSerial();
  269.  
  270.                     LogAction(LocaleString(MSG_TERMTRANSFER_LOGMSG_INITIATE_DOWNLOAD_TXT),TransferTypes[Type]);
  271.  
  272.                         /* Receive the file. */
  273.  
  274.                     if(!XProtocolReceive(XprIO))
  275.                         TransferAborted = TRUE;
  276.  
  277.                         /* In case the transfer has been aborted,
  278.                          * flush the input buffer of dirty data.
  279.                          */
  280.  
  281.                     if(TransferAborted)
  282.                         xpr_sflush();
  283.  
  284.                         /* Wake the user up. */
  285.  
  286.                     if(TransferWindow)
  287.                         WakeUp(TransferWindow,TRUE);
  288.  
  289.                     if(TransferAborted)
  290.                     {
  291.                         TransferAborted = FALSE;
  292.  
  293.                         Say(LocaleString(MSG_GLOBAL_TRANSFER_FAILED_OR_ABORTED_TXT));
  294.                     }
  295.                     else
  296.                         Say(LocaleString(MSG_GLOBAL_TRANSFER_COMPLETED_TXT));
  297.  
  298.                     Status = OldStatus;
  299.  
  300.                         /* Close the transfer panel. */
  301.  
  302.                     DeleteTransferPanel();
  303.  
  304.                         /* Queue another read
  305.                          * request.
  306.                          */
  307.  
  308.                     if(ReadRequest)
  309.                     {
  310.                         ReadRequest -> IOSer . io_Command    = CMD_READ;
  311.                         ReadRequest -> IOSer . io_Data        = ReadBuffer;
  312.                         ReadRequest -> IOSer . io_Length    = 1;
  313.  
  314.                         SetSignal(0,SIG_SERIAL);
  315.  
  316.                         SendIO(ReadRequest);
  317.                     }
  318.                 }
  319.  
  320.                 FreeAslRequest(FileRequest);
  321.             }
  322.         }
  323.     }
  324.  
  325.     if(SendAbort && UsesZModem)
  326.         SerWrite(ZModemCancel,20);
  327.  
  328.     SendAbort = FALSE;
  329.  
  330.     ReleaseWindows();
  331.  
  332.     DownloadPath = NULL;
  333.  
  334.     DidTransfer = FALSE;
  335.  
  336.     if(Config . DownloadMacro[0])
  337.         SerialCommand(Config . DownloadMacro);
  338. }
  339.  
  340.     /* StartXprSend():
  341.      *
  342.      *    Send files via xpr.
  343.      */
  344.  
  345. BYTE
  346. StartXprSend(BYTE Type)
  347. {
  348.     struct FileRequester    *FileRequest;
  349.     UBYTE             DummyBuffer[256];
  350.     BYTE             OldStatus = Status;
  351.     UBYTE            *UploadPath;
  352.     BYTE             DidSend = TRUE;
  353.  
  354.     LocalizeString(SendQuery,MSG_TERMTRANSFER_UPLOAD_FILE_TXT,MSG_TERMTRANSFER_UPLOAD_ASCII_TXT);
  355.     LocalizeString(TransferTypes,MSG_TERMTRANSFER_BINARY_TXT,MSG_TERMTRANSFER_ASCII_TXT);
  356.  
  357.         /* We are uploading data. */
  358.  
  359.     Uploading = TRUE;
  360.  
  361.         /* Select the upload path. */
  362.  
  363.     switch(Type)
  364.     {
  365.         case TRANSFER_BINARY:    UploadPath = &Config . BinaryUploadPath[0];
  366.                     break;
  367.  
  368.         case TRANSFER_TEXT:    UploadPath = &Config . TextUploadPath[0];
  369.                     break;
  370.  
  371.         case TRANSFER_ASCII:    UploadPath = &Config . ASCIIUploadPath[0];
  372.                     break;
  373.     }
  374.  
  375.     BlockWindows();
  376.  
  377.         /* If not initialized, try to set up a new
  378.          * external transfer protocol.
  379.          */
  380.  
  381.     if(!XProtocolBase)
  382.     {
  383.         NewLibrary = FALSE;
  384.  
  385.         xpr_options(0,NULL);
  386.  
  387.         if(NewLibrary)
  388.         {
  389.             if(ProtocolSetup())
  390.             {
  391.                 SaveProtocolOpts();
  392.  
  393.                 strcpy(Config . Protocol,LastXprLibrary);
  394.             }
  395.         }
  396.     }
  397.  
  398.     if(XProtocolBase)
  399.     {
  400.             /* Clear the pattern match anchor structure. */
  401.  
  402.         memset(FileAnchor,0,sizeof(struct AnchorPath));
  403.  
  404.         FileMatch = FALSE;
  405.  
  406.             /* Do we need to use our own file requester or
  407.              * will xpr handle this job for us?
  408.              */
  409.  
  410.         if(TransferBits & XPRS_NOSNDREQ)
  411.         {
  412.                 /* Open the transfer info window. */
  413.  
  414.             if(TransferPanel(SendQuery[Type]))
  415.             {
  416.                 BYTE Aborted;
  417.  
  418.                 Status = STATUS_UPLOAD;
  419.  
  420.                     /* Shut up the serial line. */
  421.  
  422.                 ClearSerial();
  423.  
  424.                 LogAction(LocaleString(MSG_TERMTRANSFER_LOGMSG_INITIATE_UPLOAD_TXT),TransferTypes[Type]);
  425.  
  426.                     /* Perform upload. */
  427.  
  428.                 if(!XProtocolSend(XprIO))
  429.                     Aborted = TRUE;
  430.                 else
  431.                     Aborted = FALSE;
  432.  
  433.                 if(TransferWindow)
  434.                     WakeUp(TransferWindow,TRUE);
  435.  
  436.                 if(Aborted)
  437.                     Say(LocaleString(MSG_GLOBAL_TRANSFER_FAILED_OR_ABORTED_TXT));
  438.                 else
  439.                     Say(LocaleString(MSG_GLOBAL_TRANSFER_COMPLETED_TXT));
  440.  
  441.                 Status = OldStatus;
  442.  
  443.                     /* Close the info window. */
  444.  
  445.                 DeleteTransferPanel();
  446.  
  447.                     /* And request another character. */
  448.  
  449.                 if(ReadRequest)
  450.                 {
  451.                     ReadRequest -> IOSer . io_Command    = CMD_READ;
  452.                     ReadRequest -> IOSer . io_Data        = ReadBuffer;
  453.                     ReadRequest -> IOSer . io_Length    = 1;
  454.  
  455.                     SetSignal(0,SIG_SERIAL);
  456.  
  457.                     SendIO(ReadRequest);
  458.                 }
  459.             }
  460.         }
  461.         else
  462.         {
  463.                 /* We will need the file requester to find
  464.                  * out which file(s) are to be transferred.
  465.                  * Multiple files and wildcards are
  466.                  * supported as well as plain file names.
  467.                  */
  468.  
  469.             if(FileRequest = GetFile(SendQuery[Type],UploadPath,"",DummyBuffer,"",FALSE,TRUE,FALSE,LocaleString(MSG_TERMTRANSFER_SEND_TXT)))
  470.             {
  471.                 strcpy(UploadPath,FileRequest -> rf_Dir);
  472.  
  473.                 if(FileRequest -> rf_NumArgs <= 1)
  474.                 {
  475.                     BPTR OldLock,NewLock;
  476.  
  477.                     MultipleFiles = FALSE;
  478.  
  479.                         /* Put the name of the first selected
  480.                          * file into the buffer.
  481.                          */
  482.  
  483.                     if(FileRequest -> rf_NumArgs == 1)
  484.                         strcpy(DummyBuffer,FileRequest -> rf_ArgList[0] . wa_Name);
  485.  
  486.                     XprIO -> xpr_filename = DummyBuffer;
  487.  
  488.                         /* To have a valid directory to
  489.                          * read the files from we'll jump
  490.                          * to the directory given in the file
  491.                          * requester. This is due to the fact
  492.                          * that all xpr protocols have referenced
  493.                          * files by their file names (sans path)
  494.                          * yet.
  495.                          */
  496.  
  497.                     if(NewLock = Lock(FileRequest -> rf_Dir,ACCESS_READ))
  498.                     {
  499.                         OldLock = CurrentDir(NewLock);
  500.  
  501.                         if(TransferPanel(SendQuery[Type]))
  502.                         {
  503.                             BYTE Aborted;
  504.  
  505.                             Status = STATUS_UPLOAD;
  506.  
  507.                             ClearSerial();
  508.  
  509.                             LogAction(LocaleString(MSG_TERMTRANSFER_LOGMSG_INITIATE_UPLOAD_TXT),TransferTypes[Type]);
  510.  
  511.                             if(!XProtocolSend(XprIO))
  512.                                 Aborted = TRUE;
  513.                             else
  514.                                 Aborted = FALSE;
  515.  
  516.                             if(TransferWindow)
  517.                                 WakeUp(TransferWindow,TRUE);
  518.  
  519.                             if(Aborted)
  520.                                 Say(LocaleString(MSG_GLOBAL_TRANSFER_FAILED_OR_ABORTED_TXT));
  521.                             else
  522.                                 Say(LocaleString(MSG_GLOBAL_TRANSFER_COMPLETED_TXT));
  523.  
  524.                             Status = OldStatus;
  525.  
  526.                             DeleteTransferPanel();
  527.  
  528.                             if(ReadRequest)
  529.                             {
  530.                                 ReadRequest -> IOSer . io_Command    = CMD_READ;
  531.                                 ReadRequest -> IOSer . io_Data        = ReadBuffer;
  532.                                 ReadRequest -> IOSer . io_Length    = 1;
  533.  
  534.                                 SetSignal(0,SIG_SERIAL);
  535.  
  536.                                 SendIO(ReadRequest);
  537.                             }
  538.                         }
  539.                         else
  540.                             MyEasyRequest(Window,LocaleString(MSG_TERMTRANSFER_FAILED_TO_LOCATE_DIRECTORY_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),FileRequest -> rf_Dir);
  541.  
  542.                         CurrentDir(OldLock);
  543.  
  544.                         UnLock(NewLock);
  545.                     }
  546.                 }
  547.                 else
  548.                 {
  549.                         /* This looks like a batch file request. */
  550.  
  551.                     if(FileRequest -> rf_NumArgs > 1)
  552.                     {
  553.                         BPTR OldLock,NewLock;
  554.  
  555.                             /* Set up the array of file names. */
  556.  
  557.                         FileCountMax    = FileRequest -> rf_NumArgs;
  558.                         FileArg        = FileRequest -> rf_ArgList;
  559.  
  560.                         MultipleFiles    = TRUE;
  561.  
  562.                             /* If this protocol doesn't support
  563.                              * batch file upload, make sure that
  564.                              * at least the first selected file
  565.                              * is transferred.
  566.                              */
  567.  
  568.                         XprIO -> xpr_filename = FileRequest -> rf_ArgList[0] . wa_Name;
  569.  
  570.                         if(NewLock = Lock(FileRequest -> rf_Dir,ACCESS_READ))
  571.                         {
  572.                             OldLock = CurrentDir(NewLock);
  573.  
  574.                             if(TransferPanel(SendQuery[Type]))
  575.                             {
  576.                                 BYTE Aborted;
  577.  
  578.                                 Status = STATUS_UPLOAD;
  579.  
  580.                                 ClearSerial();
  581.  
  582.                                 LogAction(LocaleString(MSG_TERMTRANSFER_LOGMSG_INITIATE_UPLOAD_TXT),TransferTypes[Type]);
  583.  
  584.                                 if(!XProtocolSend(XprIO))
  585.                                     Aborted = TRUE;
  586.                                 else
  587.                                     Aborted = FALSE;
  588.  
  589.                                 if(TransferWindow)
  590.                                     WakeUp(TransferWindow,TRUE);
  591.  
  592.                                 if(Aborted)
  593.                                     Say(LocaleString(MSG_GLOBAL_TRANSFER_FAILED_OR_ABORTED_TXT));
  594.                                 else
  595.                                     Say(LocaleString(MSG_GLOBAL_TRANSFER_COMPLETED_TXT));
  596.  
  597.                                 Status = OldStatus;
  598.  
  599.                                 DeleteTransferPanel();
  600.  
  601.                                 if(ReadRequest)
  602.                                 {
  603.                                     ReadRequest -> IOSer . io_Command    = CMD_READ;
  604.                                     ReadRequest -> IOSer . io_Data        = ReadBuffer;
  605.                                     ReadRequest -> IOSer . io_Length    = 1;
  606.  
  607.                                     SetSignal(0,SIG_SERIAL);
  608.  
  609.                                     SendIO(ReadRequest);
  610.                                 }
  611.                             }
  612.                             else
  613.                                 MyEasyRequest(Window,LocaleString(MSG_TERMTRANSFER_FAILED_TO_LOCATE_DIRECTORY_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),FileRequest -> rf_Dir);
  614.  
  615.                             CurrentDir(OldLock);
  616.  
  617.                             UnLock(NewLock);
  618.                         }
  619.                     }
  620.                 }
  621.  
  622.                 FreeAslRequest(FileRequest);
  623.             }
  624.             else
  625.                 DidSend = FALSE;
  626.         }
  627.  
  628.         if(FileMatch)
  629.             MatchEnd(FileAnchor);
  630.     }
  631.  
  632.     if(SendAbort && UsesZModem)
  633.         SerWrite(ZModemCancel,20);
  634.  
  635.     SendAbort = FALSE;
  636.  
  637.     ReleaseWindows();
  638.  
  639.     Uploading = FALSE;
  640.  
  641.     if(Config . UploadMacro[0])
  642.         SerialCommand(Config . UploadMacro);
  643.  
  644.     DidTransfer = FALSE;
  645.  
  646.     return(DidSend);
  647. }
  648.  
  649.     /* ASCIISetup():
  650.      *
  651.      *    Set up xprascii.library for plain ASCII file
  652.      *    transfer. This routine temporarily selects a
  653.      *    different protocol than currently set.
  654.      */
  655.  
  656. BYTE
  657. ASCIISetup()
  658. {
  659.     UBYTE Options[256];
  660.  
  661.         /* Close the currently opened xpr.library. */
  662.  
  663.     if(XProtocolBase)
  664.     {
  665.         XProtocolCleanup(XprIO);
  666.  
  667.         CloseLibrary(XProtocolBase);
  668.     }
  669.  
  670.         /* Clear the interface buffer. */
  671.  
  672.     memset(XprIO,0,sizeof(struct XPR_IO));
  673.  
  674.         /* Try to obtain the ASCII settings. */
  675.  
  676.     if(!GetEnvDOS("xprascii",Options))
  677.         Options[0] = 0;
  678.  
  679.         /* Initialize the interface buffer. */
  680.  
  681.     XprIO -> xpr_filename    = Options;
  682.     XprIO -> xpr_fopen    = (APTR)xpr_fopen;
  683.     XprIO -> xpr_fclose    = (APTR)xpr_fclose;
  684.     XprIO -> xpr_fread    = (APTR)xpr_fread;
  685.     XprIO -> xpr_fwrite    = (APTR)xpr_fwrite;
  686.     XprIO -> xpr_sread    = (APTR)xpr_sread;
  687.     XprIO -> xpr_swrite    = (APTR)xpr_swrite;
  688.     XprIO -> xpr_sflush    = (APTR)xpr_sflush;
  689.     XprIO -> xpr_update    = (APTR)xpr_update;
  690.     XprIO -> xpr_chkabort    = (APTR)xpr_chkabort;
  691.     XprIO -> xpr_gets    = (APTR)xpr_gets;
  692.     XprIO -> xpr_setserial    = (APTR)xpr_setserial;
  693.     XprIO -> xpr_ffirst    = (APTR)xpr_ffirst;
  694.     XprIO -> xpr_fnext    = (APTR)xpr_fnext;
  695.     XprIO -> xpr_finfo    = (APTR)xpr_finfo;
  696.     XprIO -> xpr_fseek    = (APTR)xpr_fseek;
  697.     XprIO -> xpr_extension    = 4;
  698.     XprIO -> xpr_options    = (APTR)xpr_options;
  699.     XprIO -> xpr_unlink    = (APTR)xpr_unlink;
  700.     XprIO -> xpr_squery    = (APTR)xpr_squery;
  701.     XprIO -> xpr_getptr    = (APTR)xpr_getptr;
  702.  
  703.         /* Open xprascii.library... */
  704.  
  705.     if(XProtocolBase = (struct Library *)OpenLibrary("xprascii.library",0))
  706.     {
  707.             /* Initialize it. */
  708.  
  709.         TransferBits = XProtocolSetup(XprIO);
  710.  
  711.             /* Successful initialization? */
  712.  
  713.         if(!(TransferBits & XPRS_SUCCESS))
  714.         {
  715.             MyEasyRequest(Window,LocaleString(MSG_GLOBAL_FAILED_TO_SET_UP_PROTOCOL_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),"xprascii.library");
  716.  
  717.             CloseLibrary(XProtocolBase);
  718.  
  719.             XProtocolBase = NULL;
  720.  
  721.             ProtocolSetup();
  722.  
  723.             return(FALSE);
  724.         }
  725.     }
  726.     else
  727.     {
  728.         MyEasyRequest(Window,LocaleString(MSG_GLOBAL_FAILED_TO_OPEN_PROTOCOL_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),"xprascii.library");
  729.  
  730.         ProtocolSetup();
  731.  
  732.         return(FALSE);
  733.     }
  734.  
  735.     BinaryTransfer = FALSE;
  736.  
  737.     return(TRUE);
  738. }
  739.  
  740.     /* ASCIIShutdown():
  741.      *
  742.      *    Close down xprascii.library and reopen the library
  743.      *    set in the current configuration.
  744.      */
  745.  
  746. VOID
  747. ASCIIShutdown()
  748. {
  749.     XProtocolCleanup(XprIO);
  750.  
  751.     CloseLibrary(XProtocolBase);
  752.  
  753.     XProtocolBase = NULL;
  754.  
  755.     BinaryTransfer = TRUE;
  756.  
  757.     ProtocolSetup();
  758. }
  759.